<?php
require_once("includes/prepend.php");
require_once("includes/lifesubnav.php");
$folders = $page->pictureFolders;
$ownerId = $page->ownerId;
$userId =$page->userId;
$options = "";
if (!empty($folders)){
	foreach ($folders as $folder){
		if (!$options){
			$options = "<option value='".$folder['id']."' selected='selected'>".$folder['name']."</option>";
		}else{
			$options .= "<option value='".$folder['id']."'>".$folder['name']."</option>";
		}
	}
}
?>
<script src="js/picture.js" type="text/javascript"></script>
<div id="maincontent"><!--start maincontent-->
	<div id="fixposition"></div>
	<div id="picturesmodule">
		<div id="controlBar">
			<span class="pictureControlB" id="pictureControlBUpload"><img src="style/sort-arrow-up.png" />上传</span>
			<span class="pictureControlB" id="pictureControlBCreate"><img style="width:15px;height:15px;" src="style/add.jpg">创建相册</span>
		</div>
		<div id="picturesNewFolder">
			<div id="closePicCreate" style="float:right;cursor:pointer;"><img src="style/window_close.png" /></div>
			相册名称：<input type="text" id="newFolderName" /><br />
			相册描述：<br /><textarea id="picturesFolderDescrip"></textarea><br />
			谁能访问：<input type="radio" name="quanxian" id="quanxian1" value="1" checked />所有人<input type="radio" name="quanxian" id="quanxian2" value="2" />密码访问<input type="radio" name="quanxian" id="quanxian3" value="3" />仅主人<br />
			<div id="picPwdDiv" style="display:none;">密码：<input type="text" id="picFolderPwd"  /></div>
			<input type="button" value="创建" id="createPicFolderB" /><input type="button" value="取消" id="createPicFolderBCancel" />
				
		</div><!-- end picturesNewFolder-->
		<div id="picUpload">
			<div id="closeUploadDiv" style="margin-top:-46px;margin-right:-53px;float:right;cursor:pointer;"><img src="style/window_close.png" /></div>
			<?php
			if ($options!="") {
			?>
				选择相册：<select name="picFolderSelect" id="picFolderSelect"><?php echo $options; ?></select>
				<div id="uploadTargetInfoDiv"></div>
				<input id="file_upload" name="file_upload" type="file" />
				<div id="endPicUpload"></div>
				<input type="button" id="uploadPics" class="uploadbuttonwhole" value="上传" >
			<?php
			}else{
				echo "您还没有创建相册呢";
			}
			?>
			
		</div>
		<div id="picFolders">
	<?php
		 if (!empty($folders)){
		 	foreach ($folders as $folder){
		 		$cover = $folder["cover"];
		 		$name  = $folder["name"];
		 		$folderId  =  $folder["id"];
		 		$number = $page->countPictures($folder["id"]);
		 		if ($cover==""){
		 			$cover = $Helper->getPicturceFolderDefaultCover();
		 		}
		 		echo "<div class='picturefolder' id='folder_$folderId'>";
		 		echo "<img src='$cover' alt='$name' onclick=\"disPlayPicS('$folderId')\" /><br />";
		 		echo $name."<br />";
		 		echo "共<span id='picturefolderInfoSpan_$folderId'>".$number."</span>张";
		 		echo "</div>";
		 	}
		 }else{
		 	echo "<h3 class='nonfolderpic'>上传照片在线分享!</h3>";
		 }
	?>
		</div><!--end picFolders-->
	</div><!--end picturesmodule-->
</div><!--end maincontent--->

<?php 
require_once("includes/pagefoot.php");
?>
<style type="text/css">
@import "uploadify/uploadify.css";
</style>
<script type="text/javascript" src="uploadify/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="uploadify/swfobject.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>

<script>
$("#closePicCreate").click(cancelPicCreateDiv);
$("#createPicFolderBCancel").click(cancelPicCreateDiv);
function cancelPicCreateDiv(){
	$("#newFolderName").val("");
	$("#picturesFolderDescrip").val("");
	$("input:radio:checked").val("");
	$("#picFolderPwd").val("");
	$("#picturesNewFolder").css({"display":"none"});
	$("#wholemark").remove();
}
$("#pictureControlBCreate").click(function(){
	if($("#picturesNewFolder").css("display")=="none"){
		$("body").append("<div id='wholemark'></div>");
		var position = HHL.getPosition();
		$("#wholemark").css({"width":position.Tw,"height":position.Th});
		var left = position.Tw/4;
		$("#picturesNewFolder").css({"position":"absolute","display":"block","left":left+"px","top":"60px"});
		
		
	}else{
		$("#picturesNewFolder").css({"display":"none"});
	}
});
$("input:radio").change(togglePwdDiv);
function togglePwdDiv(){
	if($("input:radio:checked").val()=="2"){
		$("#picPwdDiv").css({"display":"block"});
	}else{
		$("#picPwdDiv").css({"display":"none"});
	}
}

$("#createPicFolderB").click(createPicFolder);
function createPicFolder(){
	if(HHL.trim($("#newFolderName").val())==""){
		HHL.newAlertMes("请输入相册名称","z-index:12;","1500");
		$("#newFolderName").focus();
		return false;
	}
	var url = "pictureManageAjax.php";
	var data ={"name":$("#newFolderName").val(),
			   "description":$("#picturesFolderDescrip").val(),
			   "quanxian":$("input:radio:checked").val(),
			   "postType":"1",
			   "pwd":$("#picFolderPwd").val()
	};
	$.ajax({
		type:"POST",
		url:url,
		data:data,
		success:function(data){
			//$("body").append("<div id='picDymateDivBox'>"+data+"</div>");
			cancelPicCreateDiv();
			$("#picFolders").prepend(data);
			if($(".nonfolderpic").html()){
				$(".nonfolderpic").remove();
			}
		}
	})
}
</script>
